package org.karesz.code.managedbean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.karesz.code.model.User;


/**
 * 
 * This bean is managing the login / logout process with the corporation of LoginFilter servlet.filter class
 * 
 * @author gubak
 *
 */




@ManagedBean(name = "bean")
@SessionScoped
public class LoginManager {

	
	private User user;
	
	public boolean isLogged = false;
	
	
	public User getUser() {
		if(user == null) user = new User();
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	/**
	 * This method is actually checks whether the user is registered or not and according to this adjust the isLogged variable.
	 * If the user is registered then isLogged variable will be true and response will be redirected to welcome.xhtml.
	 * If the user is not registered or the user name and password are invalid, then nothing happens.
	 * 
	 * @return
	 */
	
	public String action(){
		System.out.println("Checkpoint 0");
		isLogged = true;
		System.out.println("Checkpoint 1");
		return "welcome.xhtml?faces-redirect=true";
	}
	
	/**
	 * This method will be invoked by logout.xhtml commandLink action event
	 * 
	 * 
	 * @return
	 */
	
	public String logout(){
		isLogged = false;
		return "login.xhtml";
	}
	public boolean isLogged() {
		return isLogged;
	}
	public void setLogged(boolean isLogged) {
		this.isLogged = isLogged;
	}
	
	
	
	
	
}
